/** 统计今天是今年第几天*/
let sum_day = function(year, month, day) {
    let y = year;
    let m = month;
    let d = day;
    let sum = 0;
    for (let i = 1; i < m; i++) {
        switch (i) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                sum += 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                sum += 31;
                break;
            case 2:
                sum += (((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) ? 29 : 28);
                break;
        }
    }
    return sum + d;
}

/********************************************************* */

/**求xxx年到xxx年共有多少个闰年 */
let leap_year_count = function(former_years, this_year) {
    let f_year = former_years;
    let t_year = this_year;
    let count = 0;
    for (let j = f_year - 1; j < t_year; j++) {
        if ((j % 4 == 0 && j % 100 != 0) || j % 400 == 0) {
            count++;
        }
    }
    return count;
}

/********************************************************* */

/**此时日期 */
let this_year = 2021;
let this_month = 3;
let this_day = 30;

/******************************** */

/** 统计今天是今年第几天*/
console.log('今天是2021年的第' + sum_day(this_year, this_month, this_day) + '天');
/********************************************************* */


/** 统计1901年9月7日至今所经历的天数*/
let former_year = 1901;
let former_month = 9;
let former_day = 7;
let s = this_year - former_year;
let leap_year_sum = leap_year_count(former_year, this_year);
let sum_days = s * 365 + leap_year_sum + sum_day(this_year, this_month, this_day) - sum_day(former_year, former_month, former_day);
console.log('1901年9月7日至今所经历:' + sum_days + '天');
/**统计你出生至今所经历的天数 */
let birth_years = 1999;
let birth_month = 2;
let birth_day = 3;
let ss = this_year - birth_years;
let birth_leap_year_sum = leap_year_count(birth_years, this_year);
let birth_sum_days = ss * 365 + birth_leap_year_sum - sum_day(birth_years, birth_month, birth_day) + sum_day(this_year, this_month, this_day);
console.log('出生至今所经历:' + birth_sum_days + '天');